package rdb;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.PublicKey;

public class RDBConstant {
    static {
        System.out.println("load RDBConstant");
    }
    public static final byte[] MAGIC_NUMBER = "REDIS".getBytes(StandardCharsets.UTF_8);

    public static final int MIN_VERSION = 1;
    public static final int MAX_VERSION = 10;

    public static final int OP_CODE_IDLE = 0xf8;
    public static final int OP_CODE_FREQ = 0xf9;
    public static final int OP_CODE_AUX  = 0xfa;
    public static final int OP_CODE_RESIZE_DB = 0xfb;
    public static final int OP_CODE_EXPIRE_TIME_MS = 0xfc;
    public static final int OP_CODE_EXPIRE_TIME = 0xfd;
    public static final int OP_CODE_SELECT_DB = 0xfe;
    public static final int OP_CODE_EOF = 0xff;

    public static final int LEN_6_BIT = 0;
    public static final int LEN_14_BIT = 1;
    public static final int LEN_32_OR_64_BIT = 2;
    public static final int LEN_SPECIAL = 3;
    public static final int LEN_32_BIT = 0x80;
    public static final int LEN_64_BIT = 0x81;

    public static final int STRING_ENCODE_INT_8 = 0;
    public static final int STRING_ENCODE_INT_16 = 1;
    public static final int STRING_ENCODE_INT_32 = 2;
    public static final int STRING_ENCODE_LZF = 3;

    public static final int TYPE_NONE = -1;
    public static final int TYPE_STRING = 0;
    public static final int TYPE_LIST = 1;
    public static final int TYPE_SET = 2;
    public static final int TYPE_ZSET = 3;

    public static final int TYPE_HASH = 4;
    public static final int TYPE_ZSET2 = 5;
    public static final int TYPE_MODULE = 6;
    public static final int TYPE_MODULE_2 = 7;

    public static final int TYPE_HASH_ZIP_MAP = 9;
    public static final int TYPE_LIST_ZIP_LIST = 10;

    public static final int TYPE_SET_INT_SET = 11;
    public static final int TYPE_ZSET_ZIP_LIST = 12;
    public static final int TYPE_HASH_ZIP_LIST = 13;
    public static final int TYPE_LIST_QUICK_LIST = 14;

    public static final int TYPE_STREAM_LIST_PACKS = 15;
    public static final int TYPE_HASH_LIST_PACK = 16;
    public static final int TYPE_ZSET_LIST_PACK = 17;
    public static final int TYPE_LIST_QUICK_LIST2 = 18;


    public static final int TYPE_STREAM_LIST_PACKS2 = 19;

    public static final int ZIP_STR_06B = 0;
    public static final int ZIP_STR_14B = 1;
    public static final int ZIP_STR_32B = 2;

    public static final int ZIP_INT_4B = 0x0F;
    public static final int ZIP_INT_8B = 0xFE;
    public static final int ZIP_INT_16B = 0xC0;
    public static final int ZIP_INT_24B = 0xF0;
    public static final int ZIP_INT_32B = 0xD0;
    public static final int ZIP_INT_64B = 0xE0;

    public static final String REDIS_VER = "redis-ver";
    public static final String REDIS_VER_VAL = "6.0.10";
    public static final String REDIS_BITS = "redis-bits";
    public static final String REDIS_BITS_VAL = "64";
    public static final String CTIME = "ctime";

    public static final int RANGE_6_BITS = (1 << 6) - 1;
    public static final int RANGE_14_BITS = (1 << 14) - 1;
    public static final long RANGE_32_BITS = (1L << 32) -1;
    public static final BigInteger RANGE_64_BITS = BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE);

    public static final byte LEN_14_BIT_MASK = 0b01000000;

    public static final int ENCODE_8_BIT = 0xC0;
    public static final int ENCODE_16_BIT = 0xC1;
    public static final int ENCODE_32_BIT = 0xC2;
    public static final int ENCODE_LZF = 0xc3;

    public static final int HTAB_LOG = 14;
    public static final int HTAB_SIZE = 1 << HTAB_LOG;

    public static final int MAX_OFF = 1 << 13;
    public static final int MAX_REF = (1 << 8) + (1 << 3);
    public static final int MAX_LIT = 1 << 5;

    public static final int MIN_24_BIT = (-1 << 23);
    public static final int MAX_24_BIT = (1 << 23);

    public static final int MAX_14_BIT = (1 << 14) - 1;

}
